﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace ViewModel
{
    public partial class VM_MainWindow : ObservableObject
    {
        public VM_MainWindow()
        {
            this.FirstName = "张";
            this.LastName = "san";
        }

        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(Name))]
        private string? firstName;

        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(Name))]
        private string? lastName;

        public string? Name => $"姓名是{FirstName}{LastName}";

        [ObservableProperty]
        [NotifyCanExecuteChangedFor(commandName:nameof(ChangNameCommand))]
        private bool isCan;



        [RelayCommand(CanExecute = nameof(OnIsCan))]
        private async Task OnChangName()
        {
            await Task.Delay(1500);

            this.FirstName = "张";
            this.LastName = "三";
        }

        private bool OnIsCan() => IsCan;
    }
}
